import { Input } from "antd";
import React, { Component } from "react";

export default class NumerivInput extends Component {
  onchange = (e) => {
    const { value } = e.target;
    const reg = /^([0-9]*)$/;
    if ((!Number.isNaN(value) && reg.test(value)) || value === "") {
      this.props.onChange(value);
    }
  };
  onBlur = (e) => {
    const { value } = e.target;
    const { onBlur, onChange, isDouble } = this.props;
    if (value && isDouble && value.indexOf(".00") === -1) {
      onChange(value + ".00");
    }
    if (onBlur) {
      onBlur(value);
    }
  };
  render() {
    return (
      <Input {...this.props} onChange={this.onChange} onBlur={this.onBlur} />
    );
  }
}
